require(['./config'], () => {
    require(['footer'], () => {
        class Register {
            constructor() {
                this.reg();
            }

            reg() {
                $('#reg').on('click',function () {
                    const phone = $('#phone').val();
                    const password = $('#password').val();
                    const name = $('#name').val();
                    const user = localStorage.getItem('user');
                    //有用户注册
                    if (user){
                        let arr = JSON.parse(user);
                        //判断是否已经注册
                        const isExist = arr.some(one=>{
                            return one.phone==phone
                        });
                        if (isExist){
                            alert('该手机号已被注册！')
                            return;
                        }
                        let prop={phone,password,name};
                        arr.push(prop);
                        arr=JSON.stringify(arr);
                        localStorage.setItem('user',arr);
                         window.open('/index.html');

                    }
                    //没有用户注册
                    else {
                        localStorage.setItem('user',JSON.stringify([{phone,password,name}]))
                    }
                })
            }
        }

        new Register();
    })
})